package cn.hnbjx.prepaid.common;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        // 使拦截器生效1.此处参数是我们自定义的拦截器名( ClientInterceptor ) 2.添加拦截规则(/**)拦截全部
//        registry.addInterceptor(new ClientInterceptor())
//               .addPathPatterns("/api/**")
//                .excludePathPatterns("/api/login");
//        registry.addInterceptor(new ClientInterceptor())
//                .addPathPatterns("/login/**")
//                .excludePathPatterns("/login/mp/auth")
//                .excludePathPatterns("/login/mp/login");
//        .excludePathPatterns("/api/car/**").excludePathPatterns("/api/swiper/findAll")
//        .excludePathPatterns("api/questions/getQuestions")
//        .excludePathPatterns("api/species/findSpecies")
//        .excludePathPatterns("api/phone/getPhone")
//        .excludePathPatterns()
//        ;
        registry.addInterceptor(new ClientInterceptor())
                .addPathPatterns("/api/**")
                .excludePathPatterns("/api/pay/success")
                .excludePathPatterns("/api/login/mp/auth")
                .excludePathPatterns("/api/login/mp/login")
                .excludePathPatterns("/api/upload/uploadImg")
        ;
        registry.addInterceptor(new AdminInterceptor())
                .addPathPatterns("/admin/**")
                .excludePathPatterns("/admin/login")
        ;
        WebMvcConfigurer.super.addInterceptors(registry);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 将所有/static/** 访问都映射到classpath:/static/ 目录下
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
    }

}